package com.bool.example.interceptor;

import com.bool.core.api.ApiRest;
import com.bool.core.exception.ServiceException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 * @author bool 
 * @date 2020-02-29 10:31
 */
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {

    /**
     * 通用业务异常
     * @param ex
     * @return
     */
    @ExceptionHandler(ServiceException.class)
    public ApiRest serviceExceptionHandler(ServiceException ex) {
        ex.printStackTrace();
        ApiRest apiRest = new ApiRest(ex);
        return apiRest;
    }
}
